package com.application.utils;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import com.application.component.GetUrl;

public class MethodGet {
	public StringBuffer buff			= new StringBuffer();
	GetUrl get							= new GetUrl();
	
	public boolean doGet(String url) throws IOException{
		boolean kon						= false;
		InputStream is					= null;
		URL getUrl						= new URL(get.urlGettMethod+url);
		HttpURLConnection connection	= null;
		
		/*String urlComplete				= get.urlGettMethod+url;
		getUrl							= new URL(urlComplete);*/
		
		try {
			long len					= 0;
			int ch						= 0;
			buff.delete(0, buff.length());
			
			connection					= (HttpURLConnection) getUrl.openConnection();
			is							= connection.getInputStream();
			
			len							= connection.getContentLength();
			System.out.println("Panjang Length : "+len);
			
			if(len != -1){
				for(int i=0; i<len; i++){
					if((ch = is.read()) != -1)
						buff.append((char) ch);
				}
			}else{
				while((ch = is.read()) != -1){
					len = is.available();
					buff.append((char)ch);
				}
			}
			kon 						= true;
		} catch (Exception e) {
			// TODO: handle exception
			kon							= false;
		}finally{
			is.close();
			connection.disconnect();
		}		
		return kon;
	}
}
